package com.facemox.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.facemox.bean.FaceInfo;

public interface FaceInfoMapper {

    // 1、插入一条FaceInfo数据
    @Insert("INSERT INTO face_info(face_name,face_method,face_protocol,face_body,face_host,face_url,module_id,authentication_id) values(#{faceName},#{faceMethod},#{faceProtocol},#{faceBody},#{faceHost},#{faceUrl},#{moduleId},#{authenticationId})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="faceId",keyColumn="face_id")
    int insertInterface(FaceInfo faceInfo);
    
    // 2、根据moduleId查找接口
    @Select("select * from face_info where module_id=#{moduleId} limit 0,25")
    @Results({
        @Result(column = "face_id",property = "faceId"),
        @Result(column = "face_name",property = "faceName"),
        @Result(column = "face_method",property = "faceMethod"),
        @Result(column = "face_protocol",property = "faceProtocol"),
        @Result(column = "face_body",property = "faceBody"),
        @Result(column = "face_host",property = "faceHost"),
        @Result(column = "face_url",property = "faceUrl"),
        @Result(column = "module_id",property = "moduleId"),
        @Result(column = "authentication_id",property = "authenticationId")
    })
    List<FaceInfo> getFaceListByModuleId(Integer moduleId);
    
    // 2、根据moduleId分页查询数据
    @Select("select * from face_info where module_id=#{moduleId} limit #{fromPage},#{toPage}")
    @Results({
        @Result(column = "face_id",property = "faceId"),
        @Result(column = "face_name",property = "faceName"),
        @Result(column = "face_method",property = "faceMethod"),
        @Result(column = "face_protocol",property = "faceProtocol"),
        @Result(column = "face_body",property = "faceBody"),
        @Result(column = "face_host",property = "faceHost"),
        @Result(column = "face_url",property = "faceUrl"),
        @Result(column = "module_id",property = "moduleId"),
        @Result(column = "authentication_id",property = "authenticationId")
    })
    List<FaceInfo> getFaceListByModuleIdPage(Integer moduleId,Integer fromPage,Integer toPage);
    
    // 2、查询记录总数
    @Select("select count(*) from face_info where module_id=#{moduleId}")
    int getFaceListByModuleIdCount(Integer moduleId);

    // 2、根据faceId查询FaceInfo
    @Select("select * from face_info where face_id=#{faceId}")
    @Results({
        @Result(column = "face_id",property = "faceId"),
        @Result(column = "face_name",property = "faceName"),
        @Result(column = "face_method",property = "faceMethod"),
        @Result(column = "face_protocol",property = "faceProtocol"),
        @Result(column = "face_body",property = "faceBody"),
        @Result(column = "face_host",property = "faceHost"),
        @Result(column = "face_url",property = "faceUrl"),
        @Result(column = "module_id",property = "moduleId"),
        @Result(column = "authentication_id",property = "authenticationId")
    })
    FaceInfo findFace(Integer faceId);
    
    // 3、根据faceId更新FaceInfo
    @Update("update face_info set face_name=#{faceName},face_method=#{faceMethod},face_protocol=#{faceProtocol},face_body=#{faceBody},face_host=#{faceHost},face_url=#{faceUrl},module_id=#{moduleId},authentication_id=#{authenticationId} where face_id=#{faceId}")
    int updateFace(FaceInfo faceInfo);
    
    // 4、根据faceId删除一条FaceInfo
    @Delete("delete from face_info where face_id=#{faceId}")
    int deleteFaceByFaceId(Integer faceId);
    
    // 5、查询所有接口信息
    @Select("select * from face_info")
    @Results({
        @Result(column = "face_id",property = "faceId"),
        @Result(column = "face_name",property = "faceName"),
        @Result(column = "face_method",property = "faceMethod"),
        @Result(column = "face_protocol",property = "faceProtocol"),
        @Result(column = "face_body",property = "faceBody"),
        @Result(column = "face_host",property = "faceHost"),
        @Result(column = "face_url",property = "faceUrl"),
        @Result(column = "module_id",property = "moduleId"),
        @Result(column = "authentication_id",property = "authenticationId")
    })
    List<FaceInfo> getFaceAll();
}
